package com.soushin.mvpdemo.module.rxjava;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import com.soushin.mvpdemo.R;
import com.soushin.mvpdemo.base.BaseActivity;
import com.soushin.mvpdemo.model.OperatorModel;

/**
 * Rxjava使用手册
 *
 * @author SouShin
 * @time 2018/11/16 14:38
 */
public class RxjavaActivity extends BaseActivity<RxjavaView, RxjavaPresenter> implements RxjavaView, BaseQuickAdapter.OnItemClickListener {

    @BindView(R.id.rv_example)
    RecyclerView rvExample;
    @BindView(R.id.tv_right)
    TextView tvRight;
    private RxjavaAdapter rAdapter;
    private boolean isExample;
    public static final String key_title = "title";

    @Override
    protected RxjavaPresenter createPresenter() {
        return new RxjavaPresenter();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_rxjava;
    }

    @Override
    protected void bindView() {
        getPresenter().subscribe(this);
    }

    @Override
    public void initView() {
        rAdapter = new RxjavaAdapter();
        rAdapter.setOnItemClickListener(this);
        rvExample.setLayoutManager(new LinearLayoutManager(getActivity()));
        rvExample.setHasFixedSize(true);
        rvExample.setAdapter(rAdapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        getPresenter().setDataList(isExample);
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        getPresenter().clickItem(isExample, rAdapter.getItem(position).title);
    }

    @Override
    public void setAdapter(List<OperatorModel> dataList) {
        rAdapter.setNewData(dataList);
    }

    public void setActionTitle(String title) {
        tvRight.setText(title);
    }

    @OnClick(R.id.tv_right)
    public void onViewClicked() {
        isExample = !isExample;
        getPresenter().setDataList(isExample);
    }
}
